package com.beamfield.controller.manage.portal;

import com.beamfield.common.ApiResult;
import com.beamfield.controller.common.BaseController;
import com.beamfield.enums.HttpResultEnum;
import com.beamfield.model.BeamContentWithBLOBs;
import com.beamfield.service.manage.portal.BeamContentService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;

/**
 * @author chenjj
 * @Date 2018/9/27
 */
@Controller
@RequestMapping(value = "/cms/portal/build")
public class BeamContentController extends BaseController{
    @Autowired
    BeamContentService beamContentService;

    @Value("${session.beam}")
    private String beam;
    @Value("${session.user}")
    private String user;

    @RequestMapping(value = "/beamIntro")
    public ModelAndView beamIntro(){
        return new ModelAndView();
    }
    @RequestMapping(value = "/beamGlimpse")
    public ModelAndView beamGlimpse(){
        return new ModelAndView();
    }
    @RequestMapping(value = "/systemIntro")
    public ModelAndView systemIntro(){
        return new ModelAndView();
    }
    @RequestMapping(value = "/editText")
    public ModelAndView editText(){
        return new ModelAndView();
    }

    /**
     * 获取门户建设数据
     * @param request
     * @return
     */
    @RequestMapping(value = "/readBeamContentData",method = RequestMethod.GET)
    @ResponseBody
    public ApiResult readBeamContentData(HttpServletRequest request){
        Long beamId = super.getBeamId(request);
        BeamContentWithBLOBs beamContentWithBLOBs = beamContentService.getBeamContentData(beamId);
        return new ApiResult(beamContentWithBLOBs);
    }

    /**
     * 保存门户建设
     */
    @RequestMapping(value = "/saveBeamContent", method = RequestMethod.POST)
    @ResponseBody
    public ApiResult saveBeamContent(HttpServletRequest request,String text, String type){
        if(StringUtils.isEmpty(type)){
            return new ApiResult(HttpResultEnum.MIS_PARAM.getCode(), HttpResultEnum.MIS_PARAM.getMessage());
        }
        Long userId = super.getUserId(request);
        Long beamId = super.getBeamId(request);

        return beamContentService.saveBeamContent(userId,beamId,text,type);
    }
}
